import java.io.*;

import java.net.URL;
import java.nio.file.Files;


public class TranfserImg {
    public  static String urlPrefix = "http://139.224.216.69/typora/";
    static String imgPath = "/usr/local/nginx/html/img/";
    public static void main(String[] args) {
        File file = new File("/usr/local/src/typoraImg");

        if (file.isDirectory()) {
            String[] list = file.list();
            for (String fileName : list) {
                try {
                    donlwand(fileName);
                    System.out.println(fileName + "下载成功");
                } catch (IOException exception) {
                    System.out.println(fileName + "下载失败!!!");
                }
            }

        }
    }

    private static void donlwand(String fileName) throws IOException {
        String imgUrl = urlPrefix + fileName;
        File file = new File(imgPath + fileName);
        if (file.exists()) {
            return;
        }
        InputStream inputStream = new URL(imgUrl).openStream();
        Files.copy(inputStream, file.toPath());
        inputStream.close();


    }
}
